package com.longge.wechat.controller.wx;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.longge.wechat.message.post.PostTextMessage;
import com.longge.wechat.message.post.Text;
import com.longge.wechat.message.wxUtil.WeiXinUtil;


@Controller
public class PostTextController {


	@RequestMapping(value = "/respText.do", method = RequestMethod.POST)
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String content = "";
		String openId = (String) request.getAttribute("openId");
		PostTextMessage ptm = new PostTextMessage();
		Text text = new Text();
		text.setContent("welcome to hz,你好啊！！");
		ptm.setText(text);
		ptm.setTouser(openId);
		ptm.setMsgtype("text");
		
		int result = WeiXinUtil.sendInfo(ptm);
		if(result == 1) {
			content = "发送文本消息成功";
		}
		System.out.println(content);
	}
}
